
kernel.elf：     文件格式 elf64-littleriscv


Disassembly of section .text:

0000000080000000 <_entry>:
.global _entry

# 内核入口点 - QEMU从这里开始执行
_entry:
    # 设置栈指针
    la sp, stack0           # 加载栈地址
    80000000:	00000117          	auipc	sp,0x0
    80000004:	0f010113          	add	sp,sp,240 # 800000f0 <stack0>
    li t0, 4096             # 栈大小 4KB
    80000008:	6285                	lui	t0,0x1
    add sp, sp, t0          # 设置栈顶
    8000000a:	9116                	add	sp,sp,t0
    
    # 跳转到C主函数
    call main
    8000000c:	006000ef          	jal	80000012 <main>

0000000080000010 <spin>:
    
    # 如果main返回，进入死循环
spin:
    j spin
    80000010:	a001                	j	80000010 <spin>

0000000080000012 <main>:
// 声明UART函数
void uart_putc(char c);

// C主函数 - 使用简单字符输出避免重定位问题
void main() {
    80000012:	1141                	add	sp,sp,-16
    80000014:	e406                	sd	ra,8(sp)
    80000016:	e022                	sd	s0,0(sp)
    80000018:	0800                	add	s0,sp,16
    
    uart_putc('H'); uart_putc('e'); uart_putc('l'); uart_putc('l');
    8000001a:	04800513          	li	a0,72
    8000001e:	05c000ef          	jal	8000007a <uart_putc>
    80000022:	06500513          	li	a0,101
    80000026:	054000ef          	jal	8000007a <uart_putc>
    8000002a:	06c00513          	li	a0,108
    8000002e:	04c000ef          	jal	8000007a <uart_putc>
    80000032:	06c00513          	li	a0,108
    80000036:	044000ef          	jal	8000007a <uart_putc>
    uart_putc('o'); uart_putc(' '); uart_putc('O'); uart_putc('S');
    8000003a:	06f00513          	li	a0,111
    8000003e:	03c000ef          	jal	8000007a <uart_putc>
    80000042:	02000513          	li	a0,32
    80000046:	034000ef          	jal	8000007a <uart_putc>
    8000004a:	04f00513          	li	a0,79
    8000004e:	02c000ef          	jal	8000007a <uart_putc>
    80000052:	05300513          	li	a0,83
    80000056:	024000ef          	jal	8000007a <uart_putc>
    uart_putc('!'); uart_putc('\n');
    8000005a:	02100513          	li	a0,33
    8000005e:	01c000ef          	jal	8000007a <uart_putc>
    80000062:	4529                	li	a0,10
    80000064:	016000ef          	jal	8000007a <uart_putc>
    
    while (1) {}
    80000068:	0001                	nop
    8000006a:	bffd                	j	80000068 <main+0x56>

000000008000006c <uart_init>:
#define THR 0  // 发送保持寄存器
#define LSR 5  // 线路状态寄存器
#define LSR_TX_READY (1 << 5)  // 发送就绪位

// 初始化UART
void uart_init(void) {
    8000006c:	1141                	add	sp,sp,-16
    8000006e:	e422                	sd	s0,8(sp)
    80000070:	0800                	add	s0,sp,16
    // 对于QEMU virt机器，UART通常已经初始化好
}
    80000072:	0001                	nop
    80000074:	6422                	ld	s0,8(sp)
    80000076:	0141                	add	sp,sp,16
    80000078:	8082                	ret

000000008000007a <uart_putc>:

// 输出单个字符
void uart_putc(char c) {
    8000007a:	1101                	add	sp,sp,-32
    8000007c:	ec22                	sd	s0,24(sp)
    8000007e:	1000                	add	s0,sp,32
    80000080:	87aa                	mv	a5,a0
    80000082:	fef407a3          	sb	a5,-17(s0)
    // 等待发送缓冲区为空
    while ((*REG(LSR) & LSR_TX_READY) == 0);
    80000086:	0001                	nop
    80000088:	100007b7          	lui	a5,0x10000
    8000008c:	0795                	add	a5,a5,5 # 10000005 <_entry-0x6ffffffb>
    8000008e:	0007c783          	lbu	a5,0(a5)
    80000092:	0ff7f793          	zext.b	a5,a5
    80000096:	2781                	sext.w	a5,a5
    80000098:	0207f793          	and	a5,a5,32
    8000009c:	2781                	sext.w	a5,a5
    8000009e:	d7ed                	beqz	a5,80000088 <uart_putc+0xe>
    // 发送字符
    *REG(THR) = c;
    800000a0:	100007b7          	lui	a5,0x10000
    800000a4:	fef44703          	lbu	a4,-17(s0)
    800000a8:	00e78023          	sb	a4,0(a5) # 10000000 <_entry-0x70000000>
}
    800000ac:	0001                	nop
    800000ae:	6462                	ld	s0,24(sp)
    800000b0:	6105                	add	sp,sp,32
    800000b2:	8082                	ret

00000000800000b4 <uart_puts>:

// 输出字符串
void uart_puts(const char *s) {
    800000b4:	1101                	add	sp,sp,-32
    800000b6:	ec06                	sd	ra,24(sp)
    800000b8:	e822                	sd	s0,16(sp)
    800000ba:	1000                	add	s0,sp,32
    800000bc:	fea43423          	sd	a0,-24(s0)
    while (*s) {
    800000c0:	a821                	j	800000d8 <uart_puts+0x24>
        uart_putc(*s++);
    800000c2:	fe843783          	ld	a5,-24(s0)
    800000c6:	00178713          	add	a4,a5,1
    800000ca:	fee43423          	sd	a4,-24(s0)
    800000ce:	0007c783          	lbu	a5,0(a5)
    800000d2:	853e                	mv	a0,a5
    800000d4:	fa7ff0ef          	jal	8000007a <uart_putc>
    while (*s) {
    800000d8:	fe843783          	ld	a5,-24(s0)
    800000dc:	0007c783          	lbu	a5,0(a5)
    800000e0:	f3ed                	bnez	a5,800000c2 <uart_puts+0xe>
    }
}
    800000e2:	0001                	nop
    800000e4:	0001                	nop
    800000e6:	60e2                	ld	ra,24(sp)
    800000e8:	6442                	ld	s0,16(sp)
    800000ea:	6105                	add	sp,sp,32
    800000ec:	8082                	ret
